home *** CD-ROM | disk | FTP | other *** search
- ; Example 2: Assembler Features
-
- ; This will multiply two numbers in locations "N1" and "N2" and
- ; will put the answer in location "ANS". (For it to work, the
- ; answer must be in the legal range of values. Or, if you like,
- ; it will give a correct answer MOD 2^16.)
-
- ; This program illustrates the use of the "@" directive
- ; in a program. This directive tells the computer where
- ; in memory to load the items that follow. Imagine that,
- ; for some reason, I would like my multiplication program
- ; to start at location 30 and the data for the program
- ; for the program to be at location 20. I can use the
- ; @ directive to accomplish this.
-
-
- @20 ; This says that when the program is loaded, the
- ; following item is to be at location 20. Thus,
- ; N1 will be 20, N2 will be 21, and ANS will be 22.
-
- N1: 13 ; The number 13 is stored in a location named "N1".
- N2: 56 ; 56 is in a location named "N2". These are the
- ; numbers that will be multiplied; change them
- ; to any values you like.
- ANS: data ; "ANS" is the name for a memory location that
- ; will hold the product of N1 and N2 when
- ; the program ends.
-
-
- @PC mult ; "@PC" is a special form of the @ directive that
- ; tells the computer to load the following
- ; number into the PC register as it assembles
- ; and loads this program. In this case, the
- ; value to be loaded into the PC is given by
- ; a label, "mult". The point of this is that
- ; the computer will begin execution at the
- ; location in the PC, so I want PC to be
- ; the first instruction in the program. (The
- ; value of the PC could also be set by
- ; hand, using the "Load PC" button.)
-
- @30 ; The following items -- the program itself -- will
- ; be loaded starting at location 30. (So, in fact,
- ; "mult" refers to location 30.)
-
- mult: lod-c 0 ; A program for multiplying two numbers.
- sto ANS ; (For the meaning of individual instructions,
- loop: lod N1 ; look at the end of the file "READ ME
- jmz done ; (with instructions!)".)
- shr
- sto N1
- jmf doAdd
- shift: lod N2
- shl
- jmz done
- sto N2
- jmp loop
- doAdd: lod N2
- add ANS
- sto ANS
- jmp shift
- done: hlt